package com.leo;

import com.leo.bean.Counter;
import com.leo.bean.Student;
import com.leo.simple.job.ConcurrentJob;
import com.leo.simple.job.StudentJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

/**
 * @ClassName ConcurrentJobTest
 * @Description
 * @Author wangss
 * @date 2021.07.15 10:06
 * @Version 1.0
 */
public class ConcurrentJobTest {

    public static void main(String[] args) throws SchedulerException {
        // 创建schedule实例
        Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
        scheduler.getContext().put("scheduler", "schedulerValue");

        // 创建Trigger
        Trigger t1 = TriggerBuilder.newTrigger().withIdentity("t1", "g1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever())
                .build();


        Trigger t2 = TriggerBuilder.newTrigger().withIdentity("t2", "g1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever())
                .build();

        Counter counter = new Counter(0);
        // 创建JOb实例
        JobDetail j1 = JobBuilder.newJob(ConcurrentJob.class).withIdentity("j1", "g1").build();
        j1.getJobDataMap().put("counter", counter);
        JobDetail j2 = JobBuilder.newJob(ConcurrentJob.class).withIdentity("j2", "g1").build();
        j2.getJobDataMap().put("counter", counter);

        // 加入scheduler
        scheduler.scheduleJob(j1, t1);
        scheduler.scheduleJob(j2, t2);

        scheduler.start();
    }
}
